package com.ecoolex.union.pay.retailer.job.scheduler;

import java.time.Instant;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.ecoolex.framework.scheduler.Job;
import com.ecoolex.framework.scheduler.JobComponent;
import com.ecoolex.union.pay.retailer.core.manager.UnionPayCouponManager;
import com.ecoolex.union.pay.retailer.entity.UnionPayCoupon;

@JobComponent
public class UnionPayCouponExpireCheckJob {

	@Autowired
	private UnionPayCouponManager unionPayCouponManager;
	
	@Job(name = "union.pay.UnionPayCouponExpireCheckJob.checkStatus", describe = "检查银联优惠券过期状态")
	public void check() {
		List<UnionPayCoupon> couponList = unionPayCouponManager.getExpireCoupon(Date.from(Instant.now()), 10);
		couponList.forEach(coupon -> {
			unionPayCouponManager.expireCoupon(coupon, UnionPayCouponExpireCheckJob.class.getSimpleName());
		});
	}
}
